// request
import { getThemeStates, getThemeList, deleteTheme } from '@/api/manageEnd/theme/themeList.js'

export default {
  methods: {
    async getThemeStates() {
      const res = await getThemeStates()
      const data = res.data.data || []
      this.themeStates = data
    },

    async getThemeList(params) {
      this.tableLoading = true
      const res = await getThemeList(params)
      const data = res.data.data || {}
      this.tableData = Object.freeze(
        (data.data || []).map((it) => ({
          ...it,
          editable: false,
        })),
      )
      this.pagination.total = data.count || 0
      this.tableLoading = false
    },

    async deleteTheme(id) {
      const res = await deleteTheme(id)
      const status = res.data.status
      if (status === 0) {
        this.$Message.success('删除成功')
        this.handleFormSubmit()
      } else {
        this.$Message.error(res.data.message || '删除失败，请稍后再试')
      }
    },
  },
}
